package com.zhome.gateway.config;

import com.zhome.gateway.filter.post.ResponseWrapperFilter;
import com.zhome.gateway.filter.pre.*;
import com.zhome.gateway.filter.route.HomeHostRoutingFilter;
import com.zhome.gateway.locator.MySqlClientRouteLocator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper;
import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 *
 * @author cuiyh9
 * @date 2020/5/9
 */
@Configuration
public class ZhomeGatewayConfig {

    @Autowired
    private ServerProperties serverProperties;

    @Autowired
    private ZuulProperties zuulProperties;

    @Bean
    public MySqlClientRouteLocator routeLocator() {
        return new MySqlClientRouteLocator("/" , zuulProperties);
    }

    @Bean
    public RequestPreFilter requestPreFilter() {
        return new RequestPreFilter();
    }

    @Bean
    public MockFilter mockFilter() {
        return new MockFilter();
    }

    @Bean
    public RateLimitFilter rateLimiteFilter() {
        return new RateLimitFilter();
    }

    @Bean
    public RequestDecryptFilter requestDecryptFilter() {
        return new RequestDecryptFilter();
    }

    @Bean
    public TokenValidateFilter tokenValidateFilter() {
        return new TokenValidateFilter();
    }

    @Bean
    public HomeHostRoutingFilter homeHostRoutingFilter(ProxyRequestHelper helper, ZuulProperties properties) {
        return new HomeHostRoutingFilter(helper, properties);
    }

    @Bean
    public ResponseWrapperFilter responseWrapperFilter() {
        return new ResponseWrapperFilter();
    }

}
